package second.hash;

import java.util.HashMap;

public class Solution06 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int x1 : nums1) {
            for (int x2 : nums2) {
                map.put(x1 + x2, map.getOrDefault(x1 + x2, 0) + 1);
            }
        }
        int res = 0;
        for (int x3 : nums3) {
            for (int x4 : nums4) {
                int tmp = x4 + x3;
                if (map.containsKey(-tmp)) {
                    res += map.get(-tmp);
                }
            }
        }
        return res;
    }
}
